//
//  SaveSuccessVC.m
//  DocumentWatermarking
//
//  Created by apple on 2018/9/25.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "SaveSuccessVC.h"
#import "AboutUSVC.h"
#import <WXApi.h>
#import <WeiboSDK.h>
#import <TencentOpenAPI/QQApiInterface.h>
#import <KVNProgress.h>

@interface SaveSuccessVC ()
@property (weak, nonatomic) IBOutlet UIButton *contuieBtn;
@property (weak, nonatomic) IBOutlet UIImageView *headImage;

@end

@implementation SaveSuccessVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    self.backCall = ^{
        [self.navigationController popToRootViewControllerAnimated:YES];
    };
    
    _contuieBtn.layer.cornerRadius = 22;
    _contuieBtn.layer.masksToBounds = YES;
    self.view.backgroundColor = [UIColor whiteColor];
    [self rightButtonImage:[UIImage imageNamed:@""] RightButtonTitle:@"关于我们" rightButtonTarget:self rightButtonAction:@selector(AboutUS)];
    
    _headImage.contentMode = UIViewContentModeScaleAspectFit;
    _headImage.image = _image;
}

- (IBAction)contuieAction:(UIButton *)sender {
    [self.navigationController popToRootViewControllerAnimated:YES];
}

- (IBAction)shareToQQAction:(UIButton *)sender {
    
    if ([QQApiInterface isQQInstalled]&&[QQApiInterface isQQSupportApi]) {
        [self shareTextPlatformType:UMSocialPlatformType_QQ];
    }
    else{
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"您暂未安装QQ" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil];
        [alert show];
        
    }
    
}
- (IBAction)shareToWX:(UIButton *)sender {
    
    if ([WXApi isWXAppInstalled]&&[WXApi isWXAppSupportApi]) {
        
        [self shareTextPlatformType:UMSocialPlatformType_WechatSession];
    }
    else{
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"您暂未安装微信" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil];
        [alert show];
        
    }
    
}
- (IBAction)shareToPYQ:(UIButton *)sender {
    
    if ([WXApi isWXAppInstalled]&&[WXApi isWXAppSupportApi]) {
        
        [self shareTextPlatformType:UMSocialPlatformType_WechatTimeLine];
    }
    else{
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"您暂未安装微信" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil];
        [alert show];
    }
}


/*
 *  分享的内容
 */
-(void)shareTextPlatformType:(UMSocialPlatformType)platformType{
    
    UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
    if (platformType == UMSocialPlatformType_Sina) {
        messageObject.text = @"一键添加水印，限制证件用途，防止他人恶意使用，永久使用  http://www.yiyong.com/sy/";
        UMShareImageObject * shareObject = [[UMShareImageObject alloc]init];
        shareObject.thumbImage = [UIImage imageNamed:@"shareLogo"];
        [shareObject setShareImage:[UIImage imageNamed:@"shareLogo"]];
        messageObject.shareObject = shareObject;
        
    }else{
        UMShareWebpageObject *webObject = [UMShareWebpageObject shareObjectWithTitle:@"一键添加水印，限制证件用途，防止他人恶意使用，永久使用" descr:@"证件水印助手，绿色、无毒、无广告，还能双面拼合" thumImage:[UIImage imageNamed:@"shareLogo"]];
        webObject.webpageUrl = @"http://www.yiyong.com/sy/";
        messageObject.shareObject = webObject;
    }
    
    [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:self completion:^(id result, NSError *error) {
        
        if (error) {
            
//            if (error.code == 2009) {
//                [KVNProgress showErrorWithStatus:@"用户取消分享"];
//            }
//            else{
                NSLog(@"************分享失败了 %@*********",error);
                [KVNProgress showErrorWithStatus:@"分享失败,请再次分享"];
//            }
        }else{
            NSLog(@"成功了 %@",result);
            
            if ([result isKindOfClass:[UMSocialShareResponse class]]) {
                UMSocialShareResponse *resp = result;
                //分享结果消息
                UMSocialLogInfo(@"response message is %@",resp.message);
                //第三方原始返回的数据
                UMSocialLogInfo(@"response originalResponse data is %@",resp.originalResponse);
                [[NSUserDefaults standardUserDefaults] setObject:@(1) forKey:kShareSuccess];
                [[NSUserDefaults standardUserDefaults] synchronize];
                [KVNProgress showSuccessWithStatus:@"分享成功"];
            }else{
                UMSocialLogInfo(@"response data is %@",result);
                [KVNProgress showErrorWithStatus:@"分享失败,请再次分享"];
            }
        }
    }];
}

-(void)AboutUS{
    AboutUSVC *vc =[[AboutUSVC alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}

@end
